﻿using Newtonsoft.Json.Linq;
using System;
//using System.Drawing;

using System.Collections.Generic;

using xbmc_json_async.System;
using xbmc_json_async.Utilities;

namespace xbmc_json_async.Media
{

    public class Movie : xbmc_json_async.Types.Video.Details.Movie
    {
       
        public Movie(int id, string file, string label, string thumbnail, string fanart, string plot, string director, string writer, string studio, string genre, int year, string runtime, float rating, string tagline, string plotOutline)
        {
            throw new NotImplementedException("Use static constructor and populate from Json");
            
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Movie"/> class.
        /// </summary>
        public Movie()
        {
            
        }

        /// <summary>
        /// Froms the json object.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static Movie FromJsonObject(JObject item)
        {
            var movie = new Movie();

            movie.country = XHelpers.Jval(item, "country");
            movie.director = XHelpers.Jval(item, "director");
            movie.fanart = XHelpers.Jval(item, "fanart");
            movie.file = XHelpers.Jval(item, "file");
            movie.genre = XHelpers.Jval(item, "genre");
            movie.imdbnumber = XHelpers.Jval(item, "imdbnumber");
            movie.label = XHelpers.Jval(item, "label");
            movie.lastplayed = XHelpers.Jval(item, "lastplayed");
            movie.movieid = XHelpers.JvalInt(item, "movieid");
            movie.mpaa = XHelpers.Jval(item, "mpaa");
            movie.originaltitle = XHelpers.Jval(item, "originaltitle");
            movie.playcount = XHelpers.JvalInt(item, "playcount");
            movie.plot = XHelpers.Jval(item, "plot");
            movie.plotoutline = XHelpers.Jval(item, "plotoutline");
            movie.premiered = XHelpers.Jval(item, "premiered");
            movie.productioncode = XHelpers.Jval(item, "productioncode");
            movie.rating = XHelpers.JValDouble(item, "rating");
            movie.runtime = XHelpers.Jval(item, "runtime");
            movie.showlink = XHelpers.Jval(item, "showlink");
            movie.sorttitle = XHelpers.Jval(item, "sorttitle");
            movie.studio = XHelpers.Jval(item, "studio");
            movie.tagline = XHelpers.Jval(item, "tagline");
            movie.thumbnail = XHelpers.Jval(item, "thumbnail");
            movie.title = XHelpers.Jval(item, "title");
            movie.top250 = XHelpers.JvalInt(item, "top250");
            movie.trailer = XHelpers.Jval(item, "trailer");
            movie.votes = XHelpers.Jval(item, "votes");
            movie.writer = XHelpers.Jval(item, "writer");
            movie.year = XHelpers.JvalInt(item, "year");

            /*
            Injector injector = new Injector();
            var vObj = (object)movie;
            movie = (Movie)injector.FillObject(vObj, (object)item);
            */
            return movie;
        }

        /*
        public static Movie MovieFromPlayListItem(PlaylistItem item)
        {
            Movie e = new Movie(
                item._id,
                item.File,
                item.Label,
                item.Thumbnail,
                item.Thumbnail,
                item.Plot,
                item.Director,
                item.Writer,
                item.Studio,
                item.Genre,
                item.Year,
                item.Runtime,
                item.Rating,
                item.Tagline,
                item.PlotOutline
                );
            return e;
        }
        */

        public override string ToString()
        {
            return label;
        }
    }
}
